<template>
	<view class="container bg-w">
		<view class="header uni-flex uni-row flex-between">
			<uni-nav-bar title="施工审核">
				<template slot='left'>
					<view class="flex width-100 ">
						<i class='iconfont iconfanhui' @click='goBack()'></i>
					</view>
				</template>
			</uni-nav-bar>
		</view>
		<view class="project-report position-r-top">
			<view>
				<uni-segmented-control :current="current" :values="items" @clickItem="onClickItem" style-type="text" active-color="#09AAE9"></uni-segmented-control>
				<uni-list v-for="(item,index) in auditData" :key="index" v-show="current==index">
					<uni-list-item title="基础信息" showArrow link :to="'/pages/supervise/SubitemManagement/ProjectAudit/BasicInformation/BasicInformation?projectId='+projectId"></uni-list-item>
					<uni-list-item title="工序均分" :rightText="item.score.toString()"></uni-list-item>
					<uni-list-item title="工序进度" showArrow link :to="'/pages/supervise/SubitemManagement/ProjectAudit/ProcessProgress/ProcessProgress?detailedProId='+item.detailedProId"></uni-list-item>
					<view class="explain"  v-show="item.showOperationGuide == 1 || item.showSafetyRegulations == 1 || item.showMaterials == 1">
						<text class="order">说明</text>
						<uni-list-item v-show="item.showOperationGuide == 1" title="操作指南" link @click="OperationGuideBtn(item.operationGuide)" showArrow></uni-list-item>
						<uni-list-item v-show="item.showSafetyRegulations == 1" title="安全规范" link @click="SafetyRegulationsBtn(item.safetyRegulations)"  showArrow></uni-list-item>
						<uni-list-item v-show="item.showMaterials == 1" title="物料清单" link @click="MaterialsBtn(item.materials)"  showArrow></uni-list-item>
					</view>
					<view class="explain" v-show="equipmentsData.length!=0">
						<text class="order">上传资料</text>
						<view class="">
							<uni-list-item v-for="(item,index) in equipmentsData" :key="index" :title="item.gaugingPoint" :rightText="item.auditStatusDesc" showArrow clickable @click="openConstruction(item)"></uni-list-item>
						</view>
					</view>
				</uni-list>
			</view>
		</view>
	</view>
</template>

<script>
	import { findProcess, equipments, auditSubmit } from '@/common/api/api'
	import ipConfig from '@/utils/ipConfig.js'
	export default {
		data() {
			return {
				projectId: '',
				subProjectId: '',
				// assessmentId: '',
				auditData: [], //上报数据
				items: [],
				current: 0,
				equipmentsData: [], //上传资料数据,
			}
		},
		onLoad(params) {
			console.log(params)
			this.projectId = params.projectId;
			this.subProjectId = params.subProjectId;
			// this.assessmentId = params.assessmentId;
		},
		onReady() {
			this.loadProcess();
		},
		onShow() {
			if (this.auditData.length != 0) {
				findProcess({
					projectId: this.projectId,
					subProjectId: this.subProjectId
				}).then((res) => {
					if(res.code == 20000) this.auditData = res.data;
					if(this.auditData.length >0){
						equipments(this.auditData[this.current].detailedProId).then((res) => {
							if (res.code == 20000) this.equipmentsData = res.data;
						})
					}
				})
			}
		},
		methods: {
			loadProcess() {
				findProcess({projectId: this.projectId,subProjectId: this.subProjectId}).then((res) => {
					if (res.code == 20000) {
						this.auditData = res.data;
						this.auditData.forEach((item) => {
							this.items.push(item.subProcessName);
						})
						if(this.auditData.length > 0){
							equipments(this.auditData[0].detailedProId).then((res) => {
								if (res.code == 20000) this.equipmentsData = res.data;
							})
						}
						
					}
				})
			},
			
				OperationGuideBtn(operationGuide){
					if(operationGuide){
						plus.runtime.openURL(ipConfig.ip + 'admin/sys-file/getFileById?id='+operationGuide, function(res) {
						  console.log(res);  
						});
					}else{
						uni.showToast({
							title:'暂无数据',
							icon:'none'
						})
					}
				},
				SafetyRegulationsBtn(safetyRegulations){
					if(safetyRegulations){
						plus.runtime.openURL(ipConfig.ip + 'admin/sys-file/getFileById?id='+safetyRegulations, function(res) {
						  console.log(res);  
						});
					}else{
						uni.showToast({
							title:'暂无数据',
							icon:'none'
						})
					}
				},
				MaterialsBtn(materials){
					if(materials){
						plus.runtime.openURL(ipConfig.ip + 'admin/sys-file/getFileById?id='+materials, function(res) {
						  console.log(res);  
						});
					}else{
						uni.showToast({
							title:'暂无数据',
							icon:'none'
						})
					}
				},
			onClickItem(e) {
				if (this.current !== e.currentIndex) {
					this.current = e.currentIndex;
					equipments(this.auditData[this.current].detailedProId).then((res) => {
						if (res.code == 20000) this.equipmentsData = res.data;
					})
				}
			},
			openConstruction(item) {
				uni.navigateTo({
					url: '/pages/supervise/SubitemManagement/ProjectAudit/ConstructionData/ConstructionData?standardProId='+item.standardProId+'&standardId='+item.standardId+'&auditStatus='+item.auditStatus
				})
			}
		}
	}
</script>

<style lang="less">
	.project-report /deep/ .segmented-control {
		height: 100rpx;
	}

	.submit-btn {
		// position: fixed;
		// bottom: 0;
		// left: 5%;
		width: 90%;
		margin: 20rpx auto;
		height: 80rpx;
		line-height: 80rpx;
		font-size: 28rpx;
		background-color: #09AAE9;
		color: #fff;
		border-radius: 50rpx;
	}
</style>
